package com.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sys.dao.StudentDao;
import com.sys.entity.Student;
import com.sys.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {
	@Resource
	private StudentDao studentDao;

	@Override
	public int insertStudent(String sno, Integer cid, Integer rid, Integer deptid, String cradid, String sname,
			Integer lock, String salt, String sex, Integer age, String email, String phone,
			String birthday, String natives, String seniorhigh, String createtime, String updatetime, String overtime,
			Integer del) {
		Student student = new Student();
		student.setAge(age);
		student.setBirthday(birthday);
		student.setCid(cid);
		student.setCradid(cradid);
		student.setCreatetime(createtime);
		student.setDel(del);
		student.setDeptid(deptid);
		student.setEmail(email);
		student.setLock(lock);
		student.setNatives(natives);
		student.setOvertime(overtime);
		String str = cradid;
		String password = "~"+str.substring(12);
		student.setPassword(password);
		student.setPhone(phone);
		student.setRid(rid);
		student.setSalt(salt);
		student.setSeniorhigh(seniorhigh);
		student.setSex(sex);
		student.setSname(sname);
		student.setSno(sno);
		student.setUpdatetime(updatetime);
		int len = studentDao.insertStudent(student);
		return len;
	}

	@Override
	public int deleteStudent(Integer sid) {
		Student student = new Student();
		student.setSid(sid);
		return studentDao.deleteStudent(student);
	}

	@Override
	public int updateStudent(Integer sid, String sno, Integer cid, Integer rid, Integer deptid, String cradid,
			String sname, Integer lock, String password, String salt, String sex, Integer age, String email,
			String phone, String birthday, String natives, String seniorhigh, String createtime, String updatetime,
			String overtime, Integer del) {
		Student student = new Student();
		student.setAge(age);
		student.setBirthday(birthday);
		student.setCid(cid);
		student.setCradid(cradid);
		student.setCreatetime(createtime);
		student.setDel(del);
		student.setDeptid(deptid);
		student.setEmail(email);
		student.setLock(lock);
		student.setNatives(natives);
		student.setOvertime(overtime);
		student.setPassword(password);
		student.setPhone(phone);
		student.setRid(rid);
		student.setSalt(salt);
		student.setSeniorhigh(seniorhigh);
		student.setSex(sex);
		student.setSname(sname);
		student.setSno(sno);
		student.setUpdatetime(updatetime);
		student.setSid(sid);
		return studentDao.updateStudent(student);
	}

	@Override
	public Map<String, Object> pageListStudent(Integer sid, String sno, Integer cid, Integer rid, Integer deptid,
			String cradid, String sname, Integer lock, String password, String salt, String sex, Integer age,
			String email, String phone, String birthdayStart, String birthdayEnd, String natives, String seniorhigh,
			String createtimeStart, String createtimeEnd, String updatetimeStart, String updatetimeEnd,
			String overtimeStart, String overtimeEnd, Integer del,String cname, Integer page, Integer limit) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sid", sid);
		params.put("sno", sno);
		params.put("cid", cid);
		params.put("rid", rid);
		params.put("deptid", deptid);
		params.put("cradid", cradid);
		params.put("sname", sname);
		params.put("password", password);
		params.put("salt", salt);
		params.put("sex", sex);
		params.put("age", age);
		params.put("email", email);
		params.put("phone", phone);
		params.put("birthdayStart", birthdayStart);
		params.put("birthdayEnd", birthdayEnd);
		params.put("natives", natives);
		params.put("seniorhigh", seniorhigh);
		params.put("createtimeStart", createtimeStart);
		params.put("createtimeEnd", createtimeEnd);
		params.put("updatetimeStart", updatetimeStart);
		params.put("updatetimeEnd", updatetimeEnd);
		params.put("overtimeStart", overtimeStart);
		params.put("overtimeEnd", overtimeEnd);
		params.put("del", del);
		params.put("cname", cname);
		params.put("page", (page - 1) * limit);
		params.put("limit", limit);
		List<Student> student = studentDao.pageListStudent(params);
		int count = studentDao.pageListStudentCount(params);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", student);
		map.put("count", count);
		return map;
	}

	@Override
	public Map<String, Object> getAllListStudent(Integer sid) {
		Map<String, Object> panpms = new HashMap<String, Object>();
		panpms.put("sid", sid);
		List<Student> studentList = studentDao.getAllListStudent(panpms);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", studentList);
		return map;
	}

	@Override
	public int getAllTeacherStu(Integer tid) {
		return studentDao.getAllTeacherStu(tid);
	}

}
